package by.fedorenko.sample.services.impl;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import by.fedorenko.sample.dataaccess.GuestBookDao;
import by.fedorenko.sample.datamodel.GuestBook;
import by.fedorenko.sample.services.GuestBookService;


@Service
public class GuestBookServiceImpl implements GuestBookService {
	private static final Logger LOGGER = LoggerFactory.getLogger(GuestBookServiceImpl.class);
	@Inject
	private GuestBookDao guestBookDao;
	
	
	
	
	@Override
	public GuestBook get(Long id) {
		GuestBook entity = guestBookDao.getById(id);
		return entity;
		
	}

	@Override
	public void saveOrUpdate(GuestBook guestBook) {
		if (guestBook.getId() == null) {
			LOGGER.debug("Save new: {}", guestBook);
			guestBookDao.insert(guestBook);
		} else {
			LOGGER.debug("Update: {}", guestBook);
			guestBookDao.update(guestBook);
		}
		
	}

	@Override
	public void delete(GuestBook guestBook) {
		LOGGER.debug("Remove all products");
		guestBookDao.deleteAll();
	}

	

	
}
